package com.example.administrator.qimo3no74.home;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.qimo3no74.R;

import java.util.List;

public class ButtonIconAdapter extends RecyclerView.Adapter<ButtonIconAdapter.ViewHolder> {

    private List<ButtonIcon> buttonIcons;

    static  class ViewHolder extends RecyclerView.ViewHolder{
        ImageView button_img;
        TextView button_name;

        public ViewHolder(View itemView, final Context context){
            super(itemView);
            this.button_img = itemView.findViewById(R.id.buttonIconImageView);
            this.button_name = itemView.findViewById(R.id.buttonIconImageName);

            button_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(context,""+button_name.getText(),Toast.LENGTH_SHORT).show();
                }
            });
            button_name.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(context,""+button_name.getText().toString(),Toast.LENGTH_SHORT).show();
                }
            });
        }
    }

    public ButtonIconAdapter(List<ButtonIcon> buttonIcons){
        this.buttonIcons = buttonIcons;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.button_icon_item,viewGroup,false);
        ViewHolder holder = new ViewHolder(view,viewGroup.getContext());
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        ButtonIcon buttonIcon = buttonIcons.get(i);
        viewHolder.button_img.setImageResource(buttonIcon.getButton_imgId());
        viewHolder.button_name.setText(buttonIcon.getButton_name());
    }

    @Override
    public int getItemCount() {
        return buttonIcons.size();
    }

}
